package com.hhf.feicodebackend.core.saver.template;

import com.hhf.feicodebackend.ai.model.enums.CodeGenTypeEnum;
import com.hhf.feicodebackend.ai.model.result.MultiFileCodeResult;
import com.hhf.feicodebackend.common.ErrorCode;
import com.hhf.feicodebackend.core.saver.CodeFileSaverTemplate;
import com.hhf.feicodebackend.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author hhf
 * @Date 2025/8/11
 * @Description 多文件模板
 */
public class MultiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult> {


    @Override
    protected void saveFiles(MultiFileCodeResult result, String path) {
        writeToFile(path, "index.html", result.getHtmlCode());
        writeToFile(path, "style.css", result.getCssCode());
        writeToFile(path, "script.js", result.getJsCode());
    }

    @Override
    protected CodeGenTypeEnum codeGenType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void validateInput(MultiFileCodeResult result) {
        super.validateInput(result);
        if (StringUtils.isAnyBlank(result.getHtmlCode(), result.getJsCode(), result.getCssCode())) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "multi file 代码为空");
        }
    }
}
